import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo {
    public static void main(String[] args) {
        Map<String,Integer> maps = new HashMap<>();
        maps.put("a",1);
        maps.put("b",2);
        maps.put("c",3);
        maps.put("d",4);
        maps.put("a",5);//map不重复,这条会导致前面的a的值被刷新为5
        maps.put(null,null);
        System.out.println(maps);

        //清空clear
        //判断是否为空isEmpty
        //根据键取值,get
        System.out.println(maps.get("a"));
        System.out.println(maps.get("b"));
        System.out.println(maps.get("f"));//不存在的会返回null
        System.out.println("----------------------------");
        //判断是否包含某个键
        System.out.println(maps.containsKey("a"));
        System.out.println(maps.containsKey("f"));
        System.out.println("----------------------------");
        //判断是否包含某个值
        System.out.println(maps.containsValue(1));
        System.out.println(maps.containsValue(3));
        System.out.println("----------------------------");
        //将所有的键打包为一个set
        Set<String> keys = maps.keySet();
        System.out.println(keys);
        System.out.println("----------------------------");
        //将所有的值打包为一个collection,为了保留重复值
        Collection<Integer> values = maps.values();
        System.out.println(values);
        System.out.println("----------------------------");
        //集合大小size
        //删除元素remove
        //合并其他map
        Map<String,Integer> map1 = new HashMap<>();
        Map<String,Integer> map2 = new HashMap<>();
        map1.put("java1",1);
        map1.put("java2",5);
        map2.put("java2",100);
        map2.put("java3",123);
        map1.putAll(map2);//将map2拷贝到map1
        System.out.println(map1);
        System.out.println(map2);
    }
}
